package com.tengju.bff.interfaces.covercharge.controller.provider;

import com.idanchuang.component.base.JsonResult;
import com.tengju.bff.interfaces.covercharge.constant.CoverChargeErrorCode;
import com.tengju.bff.interfaces.covercharge.dto.*;
import com.tengju.bff.interfaces.covercharge.intf.IAccountProvider;
import com.tengju.bff.interfaces.covercharge.service.IServiceAccountService;
import com.tengju.bff.interfaces.covercharge.service.IServiceCustomDetailService;
import com.tengju.bff.interfaces.covercharge.service.IServiceManageDetailService;
import com.tengju.bff.interfaces.shared.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Slf4j
@Service("accountProvider")
public class AccountProvider implements IAccountProvider {
    @Autowired
    private IServiceAccountService serviceAccountService;
    @Autowired
    private IServiceCustomDetailService serviceCustomDetailService;
    @Autowired
    private IServiceManageDetailService serviceManageDetailService;

    /**
     * 功能描述: <br>
     * 根据IDcode批量获取账户信息
     *
     * @param req 获取账户信息
     */
    @Override
    public ApiResponse<List<ServiceAccountDTO>> batchGetBalanceByIdCodes(@RequestBody QueryAccountReqDTO req) {
        Assert.isTrue(req!=null && !CollectionUtils.isEmpty(req.getIdCodeList()),"idCode不能为空");
        try {
            List<ServiceAccountDTO> resultList= serviceAccountService.getAccountInfoByIdCodes(req);
            return ApiResponse.newSuccess(resultList);
        } catch (Exception e) {
            log.error("会员组批量获取账户信息 error", e);
            return ApiResponse.newFailure(CoverChargeErrorCode.SYS_ERROR.getCode(), e.getMessage());
        }
    }

    /**
     * 功能描述: <br>
     * 根据IDCode和类型获取账户信息
     *
     * @param req 获取账户信息
     */
    @Override
    public ApiResponse<ServiceAccountDTO> batchGetBalanceByIdCodeAndType(@RequestBody QueryAccountReqDTO req) {
        Assert.notNull(req.getIdCode(),"IdCode不能为空");
        Assert.notNull(req.getAccountType(),"账户类型不能为空");
        try {
            ServiceAccountDTO accountInfoVo= serviceAccountService.batchGetBalanceByIdCodeAndType(req);
            return ApiResponse.newSuccess(accountInfoVo);
        } catch (Exception e) {
            log.error("会员组单个获取账户信息 error", e);
            return ApiResponse.newFailure(CoverChargeErrorCode.SYS_ERROR.getCode(), e.getMessage());
        }
    }

    /**
     * 功能描述: <br>
     * 根据IDCode和表id获取客戶明細
     *
     * @param req 获取账户信息
     */
    @Override
    public ApiResponse<List<ServiceCustomDetailDTO>> getListFromIdCodeAndTableIdList(@RequestBody QueryCustomDetailReqDTO req) {
        Assert.notNull(req.getIdCode(),"IdCode不能为空");
        try {
            List<ServiceCustomDetailDTO> serviceCustomDetail= serviceCustomDetailService.getListFromIdCodeAndTableIdList(req);
            return ApiResponse.newSuccess(serviceCustomDetail);
        } catch (Exception e) {
            log.error("会员组根据IDCode和表id获取客戶明細 error", e);
            return ApiResponse.newFailure(CoverChargeErrorCode.SYS_ERROR.getCode(), e.getMessage());
        }
    }

    /**
     * 功能描述: <br>
     * 获取客戶明細
     *
     * @param req 获取账户信息
     */
    @Override
    public ApiResponse<List<ServiceCustomDetailDTO>> getCustomDetailList(@RequestBody QueryCustomDetailReqDTO req) {
        Assert.notNull(req.getIdCode(),"idCode不能为空");
        try {
            List<ServiceCustomDetailDTO> serviceCustomDetail= serviceCustomDetailService.getCustomDetailList(req);
            return ApiResponse.newSuccess(serviceCustomDetail);
        } catch (Exception e) {
            log.error("会员组获取客戶明細 error", e);
            return ApiResponse.newFailure(CoverChargeErrorCode.SYS_ERROR.getCode(), e.getMessage());
        }
    }

    /**
     * 功能描述: <br>
     * 根据IDCode和表id获取管理明細
     *
     * @param req 获取账户信息
     */
    @Override
    public ApiResponse<List<ServiceManageDetailDTO>> getManageListFromIdCodeAndTableIdList(@RequestBody QueryManageDetailReqDTO req) {
        Assert.notNull(req.getIdCode(),"IdCode不能为空");
        try {
            List<ServiceManageDetailDTO> ServiceManageDetailVo= serviceManageDetailService.getListFromIdCodeAndTableIdList(req);
            return ApiResponse.newSuccess(ServiceManageDetailVo);
        } catch (Exception e) {
            log.error("会员组根据IDCode和表id获取客戶明細 error", e);
            return ApiResponse.newFailure(CoverChargeErrorCode.SYS_ERROR.getCode(), e.getMessage());
        }
    }

    /**
     * 功能描述: <br>
     * 根据IDCode和表id获取管理明細
     *
     * @param req 获取账户信息
     */
    @Override
    public ApiResponse<List<ServiceManageDetailDTO>> getManageDetailList(@RequestBody QueryManageDetailReqDTO req) {
        Assert.notNull(req.getIdCode(),"idCode不能为空");
        try {
            List<ServiceManageDetailDTO> ServiceManageDetailVo= serviceManageDetailService.getManageDetailList(req);
            return ApiResponse.newSuccess(ServiceManageDetailVo);
        } catch (Exception e) {
            log.error("会员组根据IDCode和表id获取客戶明細 error", e);
            return ApiResponse.newFailure(CoverChargeErrorCode.SYS_ERROR.getCode(), e.getMessage());
        }
    }
}
